<?php

class Fe_forwarding_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get_all_cate() {
        $db = $this->load->database('default', TRUE);
        $db->order_by("order", "asc");
        $query = $db->get('forwarding_cate');
        $result = $query->result();
        return $result;
    }

    function get_list_articles($title, $cate, $page_size, $page_index){
        $db = $this->load->database('default', TRUE);

        //get row number
        if($title != ""){
            $db->like('title', $title);
        }
        if($cate != 0){
            $query = $db->get_where("forwarding", array("cate" => $cate));
        }
        else{
            $query = $db->get('forwarding');
        }
        $count = $query->num_rows();

        //get result with paging
        $db->order_by("order", "asc");
        if($title != ""){
            $db->like('title', $title);
        }
        if($cate != 0){
            $query = $db->get_where("forwarding", array("cate" => $cate), $page_size, $page_index);
        }
        else{
            $query = $db->get('forwarding', $page_size, $page_index);
        }

        $result = $query->result();
        return array($count, $result);
    }
    
    function get_article_by_id($id){
        $db = $this->load->database('default', TRUE);
        $query = $db->get_where('forwarding', array("id" => $id));
        $result = $query->result();
        return $result;
    }
}

?>